using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
using System.Threading;

namespace SpoonCore.Simulation
{
	class StartSimulation : ISimulation
	{
		private List<SpoonClient> _clientList = new List<SpoonClient>();
		private SpoonClient _server = new SpoonClient(1000);

		public void Run()
		{
			int count = 10;

			_server.Start();

			Thread.Sleep(250);

			while (count > 0)
			{
				SpoonClient client = new SpoonClient();
				client.AddBootstrap(new IPEndPoint(IPAddress.Loopback, 1000));
				client.Start();
				_clientList.Add(client);

				Thread.Sleep(25);
				Console.WriteLine(client.Id);

				count--;
			}

			Console.WriteLine("Press enter to abort...");
			Console.ReadLine();
			_server.Dispose();
		}

		public void Pause()
		{ }

		public void Resume()
		{ }

		public List<SpoonClient> Clients
		{
			get
			{
				List<SpoonClient> res = new List<SpoonClient>();
				res.AddRange(_clientList);
				res.Add(_server);
				return res;
			}
		}
	}
}
